#include <iostream>

using namespace std;

template <typename NUM>
void print_array(NUM arr[], int len)
{
	for (int idx = 0; idx < len; idx += 1)
	{
		cout << arr[idx] << " ";
	}
	cout << endl;
}

template <typename NUM>
void bubble_sort(NUM arr[], int len)
{
	for (int i = 0; i < len; i += 1)
	{
		for (int j = 0; j < len - i - 1; j += 1)
		{
			if (arr[j] > arr[j+1])
			{
				NUM tmp = arr[j];
				arr[j] = arr[j+1];
				arr[j+1] = tmp;
			}
		}
	}
}

int main()
{
	int arr1[] = {9, 8, 7, 6, 5, 4, 3, 2, 1};
	char arr2[] = {'f', 'e', 'd', 'c', 'b', 'a'};

	cout << "Before: ";
	print_array(arr1, sizeof(arr1) / sizeof(int));
	bubble_sort(arr1, sizeof(arr1) / sizeof(int));
	cout << "After:  ";
	print_array(arr1, sizeof(arr1) / sizeof(int));

	cout << "Before: ";
	print_array(arr2, sizeof(arr2) / sizeof(char));
	bubble_sort(arr2, sizeof(arr2) / sizeof(char));
	cout << "After:  ";
	print_array(arr2, sizeof(arr2) / sizeof(char));

	return 0;
}
